# utils/screenshot_utils.py
import datetime
import os


def save_screenshot(driver, name="screenshot"):
    """保存截图到 screenshots 目录"""
    timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = f"{name}_{timestamp}.png"
    path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "screenshots")
    if not os.path.exists(path):
        os.makedirs(path)
    driver.save_screenshot(os.path.join(path, filename))
    return filename
